class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        unordered_map<char,int>hash1;
        for(auto& x:p)
        hash1[x]++;
        vector<int>ret;
        unordered_map<char,int>hash2;
        for(int left=0,right=0;right<s.size();right++)
        {
            auto ch=s[right];
            hash2[ch]++;
            while(hash2[ch]>hash1[ch])
            {
                hash2[s[left++]]--;
            }
            if(hash1==hash2)
            {
                ret.push_back(left);
            }
        }
        return ret; 
    }
};
